package fr.cnam.projetSiw.client.structure.pages.suggest;

import java.util.ArrayList;

import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.EventBus;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.AcceptsOneWidget;

import fr.cnam.projetSiw.client.core.ClientFactory;
import fr.cnam.projetSiw.client.core.GeolocationManager;
import fr.cnam.projetSiw.client.core.ZicActivity;
import fr.cnam.projetSiw.client.services.LastFmService;
import fr.cnam.projetSiw.client.services.LastFmServiceAsync;
import fr.cnam.projetSiw.shared.Artist;

public class TopArtistActivity extends ZicActivity implements TopArtistView.Presenter
{

	private LastFmServiceAsync lastFmService = GWT.create(LastFmService.class);

	public TopArtistActivity(ClientFactory clientFactory)
	{
		super(clientFactory);
	}

	@Override
	public void start(AcceptsOneWidget panel, EventBus eventBus)
	{
		final TopArtistView view = clientFactory.getTopArtistView();
		view.setPresenter(this);
		panel.setWidget(view);

		GeolocationManager manager = GeolocationManager.getInstance();

		lastFmService.getHypeArtistByCity(manager.getCity(), new AsyncCallback<ArrayList<Artist>>()
		{

			@Override
			public void onFailure(Throwable caught)
			{
				// TODO Auto-generated method stub

			}

			@Override
			public void onSuccess(ArrayList<Artist> result)
			{
				if (result != null)
					view.setData(result);
			}
		});


	}
}
